package demo04;

public class Student {
    //姓名, 语文成绩, 数学成绩, 英语成绩
    private String name;
    private int chineseGrade;
    private int mathGrade;
    private int englishGrade;

    public Student() {
    }

    public Student(String name, int chineseGrade, int mathGrade, int englishGrade) {
        this.name = name;
        this.chineseGrade = chineseGrade;
        this.mathGrade = mathGrade;
        this.englishGrade = englishGrade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChineseGrade() {
        return chineseGrade;
    }

    public void setChineseGrade(int chineseGrade) {
        this.chineseGrade = chineseGrade;
    }

    public int getMathGrade() {
        return mathGrade;
    }

    public void setMathGrade(int mathGrade) {
        this.mathGrade = mathGrade;
    }

    public int getEnglishGrade() {
        return englishGrade;
    }

    public void setEnglishGrade(int englishGrade) {
        this.englishGrade = englishGrade;
    }

    //他们都要吃饭, 睡觉和学习.
    public void eat() {
        System.out.println("吃饭!");
    }

    public void sleep() {
        System.out.println("睡觉!");
    }

    public void study() {
        System.out.println("学习!");
    }

    @Override
    public String toString() {
        return "姓名为" + getName() + "的同学, 语文成绩为" + getChineseGrade()
                + "分, 数学成绩为" + getMathGrade() + "分, 英语成绩为" + getEnglishGrade() + "分";
    }

    //分数最高的学生是张三, 总分为300分, 其中语文成绩为100分, 数学成绩为100分, 英语成绩为100分.
    public int getAllGradeSum() {
        return chineseGrade + englishGrade + mathGrade;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (chineseGrade != student.chineseGrade) return false;
        if (mathGrade != student.mathGrade) return false;
        if (englishGrade != student.englishGrade) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + chineseGrade;
        result = 31 * result + mathGrade;
        result = 31 * result + englishGrade;
        return result;
    }
}
